// 引入mongoose
let mongoose = require("mongoose")

// 1. 引入约束 Schema
let Schema = mongoose.Schema
// 2. 创建一个约束对象实例
let studentSchema = new Schema({
    stu_id: {
        type: String,
        require: true,
        unique: true
    },
    name: {
        type: String,
        require: true,
    },
    age: {
        type: Number,
        require: true,
    },
    sex: {
        type: String,
        require: true
    },
    hobby: [String],
    info: {
        type: Schema.Types.Mixed // 接收所有类型
    },
    date: {
        type: Date,
        default: Date.now()
    },
    enable_flag: {
        type: String,
        default: "Y"
    }
})
// 3.创建模型对象
// 第一个参数与数据库中的集合相对应, 第二个参数指定约束实例对象
let studentModel = mongoose.model("students", studentSchema)